package graph

import "fmt"

var visited [10]int

type Node struct {
	Val       int
	Neighbors []*Node
}

type Graph struct {
	Ves        [10]int
	Arc        [10][10]int
	NumV, NumE int
}

func DFS(g Graph, i int) {
	visited[i] = 1
	fmt.Println("访问", i)
	for j := 0; j < g.NumV; j++ {
		if g.Arc[i][j] != 0 && visited[j] == 0 {
			DFS(g, j)
		}
	}
}

func DFSTraverse(g Graph) {
	for i := 0; i < g.NumV; i++ {
		if visited[i] == 0 {
			DFS(g, i)
		}
	}
}

func BFS(g Graph, i int) {

	var queue []int
	queue = append(queue, i-1)
	for len(queue) != 0 {
		node := queue[0]
		visited[node] = 1
		fmt.Printf("node: %v\n", node+1)
		queue = queue[1:]
		for j := 0; j < g.NumV; j++ {
			if g.Arc[node][j] == 1 && visited[j] == 0 {
				queue = append(queue, j)
			}
		}
	}
}
